
#ifndef __PARSER_H__
#define __PARSER_H__

#include <stdlib.h>
#include <betty/terminal.h>
#include "parser_tab.h"

#define PARSER_PARAM_MAX        16


struct ParserData {
        enum ActionID   action; /* action to perform */
        Betty_Character final;  /* final character */
        
        /* parameters */
        int     parm_count;
        int     parm_value[PARSER_PARAM_MAX];
        int     parm_overflow;

        /* intermediate character buffer. imed_buf is always
	   0-terminated! */
        char    imed_buf[10];
        int     imed_len;
        int     imed_overflow;
};


typedef void (* parser_callback_t)(void *, struct ParserData *);


struct Parser {
        const struct State      *state;  /* current parser state */
        struct ParserData       data;
        parser_callback_t       cb;
        void                    *cb_arg; 
};


void parser_init (struct Parser *p, parser_callback_t cb, void *cb_arg);
void parser_cleanup (struct Parser *p);
void parser_in (struct Parser *p, Betty_Character uc);

#ifdef DEBUG
void parser_dump (const char *prefix, const struct ParserData *d);
#endif

#endif


